<template>
	<view class="charts-box">
		<u-gap height="20" bgColor="#F5F7FA"></u-gap>	
		<view style="text-align: center; padding: 20px 0">{{ titleValue }}</view>
		<qiun-data-charts type="line" :opts="opts1" :chartData="chartData" ontouch canvas2d />
		<view class="table-con" :class="[isShow ? 'height-all' : 'height-init']">
			<view v-for="(item, index) in (slipCasting.tableList || [])" :key="index">
				<view class="top">
					<view class="title">时间</view>
					<view class="num" v-for="(item1, index1) in item.dateArray" :key="index1">{{ item1 }}</view>
				</view>
				<view class="top" v-for="(item1, index1) in item.dataArray" :key="index1" :class="index1 % 2 === 0 ? 'white' : 'weight'">
					<view class="title">{{ item1.label }}</view>
					<view class="num" v-for="(item2, index2) in item1.dataList" :key="index2">{{ item2 }}</view>
				</view>
			</view>
		</view>
		<view @click="isShow = !isShow" class="text-operation">
			<view style="margin: auto; display: flex; align-items: center">
				<view class="img-down"></view>
				<view>{{ isShow ? '收起' : '展开查看全部' }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import QiunDataCharts from '../../components/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue';
	export default {
		components: {
			QiunDataCharts
		},
		props: {
			titleValue: {
				type: String,
				default: '差异沉降情况'
			},
			yTitle: {
				type: String,
				default: '沉降量/mm'
			},
			slipCasting: {
				type: Object,
				default: () => ({})
			}
		},
		data() {
			return {
				tableList: [],
				isShow: false,
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['area'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts1: {
					color: ['#1890FF', '#91CB74', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
					padding: [20, 30, 0, 15],
					type: 'line',
					dataLabel: false,
					enableScroll: true, // 是否开启滚动
					legend: {
						position: 'bottom',
						float: 'left',
						padding: 15,
						itemGap: 12 //展示之间的间隔
					},
					label: {
					   show: false,
					},
					xAxis: {
						disableGrid: true,  // 禁用网格线
						scrollShow: true,   // 开启横向滚动
						scrollAlign: 'left', // 滚动后左对齐
						axisLine: true,
						boundaryGap: 'justify',
						gridType: 'dash',
						gridEval: 1,
						gridColor:"#1890ff",
						dashLength: 4,
						calibration:true, //坐标轴刻度线
						itemCount: 4
						// disabled: false,
						// splitNumber:2
						// scrollShow:true,
						// format: "xAxisDemo2"
					},
					yAxis: {
						gridType: 'dash',
						disableGrid: true,
						dashLength: 2,
						showTitle: true,
						data: [
							{
								title: this.yTitle,
								titleFontSize: 14,
								titleOffsetY: -10,
								titleOffsetX: 10
							}
						]
					},
					extra: {
						line: {
							type: 'curve',
							opacity: 0.2,
							addLine: true,
							width: 2,
							gradient: true,
							activeType: 'none'
						},
						tooltip: {
							showBox: false,
							showArrow: false,
							showCategory: false,
							xAxisLabel: false
						},
						markLine: {
							type: 'dash'
						}
					}
				}
			};
		},
		watch: {
			slipCasting: function() {
				this.getServerData()
			}
		},
		methods: {
			getServerData() {
				if (!this.slipCasting || !this.slipCasting.dateArray || !this.slipCasting.dataArray) {
					return 
				}
				const { dateArray, dataArray } = this.slipCasting
				this.chartData = {
					categories: dateArray.length ? dateArray : ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00'],
					series: dataArray.map(item => ({
						name: item.label,
						data: (item.dataList || []).map(item1 => item1.data),
						color: item.color,
						labelShow: false,
						lineType: 'solid', 
						textColor: '#FFFFFF', 
						pointShape: 'none', 
						legendShape: 'rect'
					}))
				};
			}
		}
	};
	
</script>

<style lang="scss" scoped>
.table-con {
	padding:0 20px 20px 20px;
	overflow-y: hidden;
	.top {
		display: flex;
		align-items: center;
		padding: 12px 10rpx;
		text-align: center;
		color: #000000;
		font-size: 16px;
		font-weight: bold;
		background: #f5f7fa;
		&:first-child {
			margin-top: 20px;
		}
		.title {
			width: 60px;
			
		}
		.num {
			width: 58px;
		}
		&.weight {
			font-weight: 500;
			color: #445469;
		}
		&.white {
			background-color: #ffffff;
			color: #445469;
			font-weight: 500;
		}
	}
}
.text-operation {
	display: flex;
	align-items: center;
	color: #2f80ed;
	font-weight: 500;
	font-size: 16px;
	padding: 20px 0;
	.img-down {
		height: 20px;
		width: 20px;
		background: url('@/subpackage-overhaul/static/down.png') no-repeat 100% 100%;
		margin-right: 5px;
	}
}
.height-all {
	max-height: initial; //这是啥意思  回到初始化的状态
}
.height-init {
	max-height: 150px;
}
</style>